請依使用者故事
作為一名圖書管理員,我希望能在系統中新增、編輯和刪除書籍資料,包括書名、作者、ISBN、分類和庫存數量,以便精確管理館藏。
這是第一個使用者故事
請協助產生模組對應的model view
並且提供清晰的目錄結構
library_management/
├── __init__.py
├── __manifest__.py
├── models/
│ ├── __init__.py
│ ├── library_book.py
│ └── library_book_category.py
├── views/
│ ├── library_book_views.xml
│ └── library_book_category_views.xml
└── security/
└── ir.model.access.csv
__init__.py
library_management/__init__.py
from . import models
library_management/models/__init__.py
from . import library_book
from . import library_book_category
__manifest__.py
這個檔案定義了模組的基本資訊,包括名稱、描述、所依賴的模組等。
library_management/__manifest__.py
{
'name': 'Library Management',
'version': '1.0',
'category': 'Library',
'summary': 'Manage books and categories in a library.',
'depends': ['base'],
'data': [
'security/ir.model.access.csv',
'views/library_book_views.xml',
'views/library_book_category_views.xml',
],
'installable': True,
'application': True,
}
library_book.py
這個檔案定義了 library.book
模型。
library_management/models/library_book.py
from odoo import models, fields
class LibraryBook(models.Model):
_name = 'library.book'
_description = 'Library Book'
name = fields.Char(string='Book Title', required=True)
author = fields.Char(string='Author', required=True)
isbn = fields.Char(string='ISBN', required=True)
category_id = fields.Many2one('library.book.category', string='Category')
stock_qty = fields.Integer(string='Stock Quantity', required=True)
description = fields.Text(string='Description')
library_book_category.py
這個檔案定義了 library.book.category
模型。
library_management/models/library_book_category.py
from odoo import models, fields
class LibraryBookCategory(models.Model):
_name = 'library.book.category'
_description = 'Book Category'
name = fields.Char(string='Category Name', required=True)
description = fields.Text(string='Description')
library_book_views.xml
這個檔案定義了 library.book
模型的視圖。
library_management/views/library_book_views.xml
<odoo>
<record id="view_library_book_tree" model="ir.ui.view">
<field name="name">library.book.tree</field>
<field name="model">library.book</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="author"/>
<field name="isbn"/>
<field name="category_id"/>
<field name="stock_qty"/>
</tree>
</field>
</record>
<record id="view_library_book_form" model="ir.ui.view">
<field name="name">library.book.form</field>
<field name="model">library.book</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="author"/>
<field name="isbn"/>
<field name="category_id"/>
<field name="stock_qty"/>
</group>
<group>
<field name="description"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_library_book" model="ir.actions.act_window">
<field name="name">Books</field>
<field name="res_model">library.book</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_library_root" name="Library"/>
<menuitem id="menu_library_books" name="Books" parent="menu_library_root" action="action_library_book"/>
</odoo>
library_book_category_views.xml
這個檔案定義了 library.book.category
模型的視圖。
library_management/views/library_book_category_views.xml
<odoo>
<record id="view_library_book_category_tree" model="ir.ui.view">
<field name="name">library.book.category.tree</field>
<field name="model">library.book.category</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="description"/>
</tree>
</field>
</record>
<record id="view_library_book_category_form" model="ir.ui.view">
<field name="name">library.book.category.form</field>
<field name="model">library.book.category</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="description"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_library_book_category" model="ir.actions.act_window">
<field name="name">Book Categories</field>
<field name="res_model">library.book.category</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_library_categories" name="Categories" parent="menu_library_root" action="action_library_book_category"/>
</odoo>
security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_library_book,access.library.book,model_library_book,,1,1,1,1
access_library_book_category,access.library.book.category,model_library_book_category,,1,1,1,1
library_management
資料夾:在您的 Odoo 模組目錄中新增 library_management
資料夾。models/
, views/
, security/
和 __init__.py
, __manifest__.py
檔案放置在相對應的資料夾中。Library Management
模組。這樣的結構使模型、視圖和安全性更加清晰,模組可擴展性更強。
__init__.py
內容__manifest__.py
內容addons_path =odoo-17.0\addons,odoo-17.0\odoo\addons,addons
!
https://ithelp.ithome.com.tw/upload/images/20240919/20102255gNJpYfFc9K.jpg
上述的ChatGPT的內容,皆一行未調整的狀況,直接複製貼上至Pycharm且安裝至odoo17執行無誤,証明ChatGPT確實可協助程式人員進行開發,而不是單純的補完程式碼,後續有更複雜的運用,皆是透過對談的方式由ChatGPT思考及產生程式碼,敬請期待